package nc.ui.arap.buttonstat;

import nc.ui.arap.engine.AbstractRuntime;
import nc.ui.arap.engine.ExtButtonObject;
import nc.ui.arap.engine.IActionRuntime;
import nc.ui.arap.engine.IButtonStatus;
import nc.ui.arap.global.DjTempletHelper;
import nc.ui.ep.dj.ArapBillWorkPageConst;
import nc.vo.ep.dj.DJZBHeaderVO;
import nc.vo.ep.dj.DJZBVO;

public class DjRelQryListStatListener implements IButtonStatus {

	public void updateButtonStatus(ExtButtonObject bo, IActionRuntime runtime) {
		// TODO Auto-generated method stub
		if(!(runtime instanceof AbstractRuntime))
			return ;
		AbstractRuntime runt=(AbstractRuntime)runtime;
		bo.setEnabled(false);
		
		if (runt.getCurrWorkPage()==ArapBillWorkPageConst.CARDPAGE&&!DjTempletHelper.isCardInQuery(runt))  
			return ;
		
		DJZBVO djvo=null;
		if (runt.getCurrWorkPage()==ArapBillWorkPageConst.CARDPAGE) {
			djvo =runt. getDjDataBuffer().getCurrentDJZBVO();
		} else {
			int row_h = DjTempletHelper.getBillListPanel(runt).getHeadTable()
					.getSelectedRow();
			if (row_h >= 0) {
				if (DjTempletHelper.getBillListPanel(runt).getHeadBillModel().getValueAt(
						row_h, "vouchid") != null) {
					String vouchid = DjTempletHelper.getBillListPanel(runt)
							.getHeadBillModel().getValueAt(row_h, "vouchid")
							.toString();
					djvo = runt.getDjDataBuffer().getDJZBVO(vouchid);
				}
			}

		}
		if (djvo != null) {
			DJZBHeaderVO head = (DJZBHeaderVO) djvo.getParentVO();
			if ("fk".equalsIgnoreCase(head.getDjdl())
					|| "sk".equalsIgnoreCase(head.getDjdl())
					|| "ys".equalsIgnoreCase(head.getDjdl())
					|| "yf".equalsIgnoreCase(head.getDjdl())){
				bo.setEnabled(true);
				bo.setVisible(true);//
			}
		}
	}

}
